﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CsplCalculatorLib.Interface;
using CsplCalculatorLib.Model;

namespace CsplCalculatorLib
{
    public class MainCalculator
    {
        #region Private Fields

            private IBasicCalculator _calculator;    
            private CalModel _data;

        #endregion

        #region Constructors

            public MainCalculator()
            {
                this._calculator = new BasicCalculator();

            }
        #endregion

        #region Properties

            public CalModel Data
            {
                get { return _data; }
                set { _data = value; }
            }

        #endregion

        #region Methods

            public int Calculate() 
            {
                if (this.Data != null)
                {
                    if (this.Data.CalMode == CalMode.Simple)
                    {
                        switch (this.Data.Operation)
                        {
                            case CalOperations.Add:
                                return this._calculator.Add(this.Data.IntegerValue1, this.Data.IntegerValue2);
                            case CalOperations.Mul:
                                return this._calculator.Mul(this.Data.IntegerValue1, this.Data.IntegerValue2);
                            case CalOperations.Div:
                                return this._calculator.Div(this.Data.IntegerValue1, this.Data.IntegerValue2);
                            case CalOperations.Sub:
                                return this._calculator.Sub(this.Data.IntegerValue1, this.Data.IntegerValue2);
                            default:
                                Console.WriteLine("Invalid operation");
                                return 0;
                        }
                    }
                    else 
                    {
                        return this._calculator.ComplexListOperation(this.Data.ListOfNumber, this.Data.Operation);     
                    }
                }
                else
                {
                    Console.WriteLine("data is null!");
                    return 0;
                }
            }

        #endregion
    }
    public enum CalOperations { Add, Mul, Div, Sub , AddList};
    public enum CalMode { Simple, List };
}
